﻿using System;
using ASPNETVN.PORTAL.Components.UI;
using System.Net;
using System.IO;
using HtmlAgilityPack;

namespace ThoiTiet.Modules.ProvinceWeather.Controls
{
    public partial class DetailProvinceWeather : ModulePage
    {
        //protected string GetHTMLFromUrl(string Url)
        //{
        //    HttpWebRequest req;
        //    HttpWebResponse res = null;
        //    string strHTML = string.Empty;
        //    try
        //    {
        //        req = (WebRequest.Create(Url) as HttpWebRequest);
        //        if (req != null)
        //        {
        //            req.AllowAutoRedirect = true;
        //            req.Method = "GET";
        //            res = req.GetResponse() as HttpWebResponse;
        //        }
        //        if (res != null)
        //            using (Stream s = res.GetResponseStream())
        //            {
        //                using (StreamReader sr = new StreamReader(s))
        //                {
        //                    strHTML = sr.ReadToEnd();
        //                }
        //            }
        //    }
        //    catch
        //    {
        //        if (res != null)
        //        {
        //            res.Close();
        //        }
        //    }

        //    if (res != null)
        //        res.Close();
        //    return strHTML;
        //}

        //protected void GetProvinceWeather(string strItemID)
        //{
        //    string content = GetHTMLFromUrl("http://www.nchmf.gov.vn/website/vi-VN/62" + strItemID + "/map/Default.aspx");
        //    int begin = content.IndexOf("_ctl1__ctl0_ModulePane_199");
        //    int end = content.Substring(begin).IndexOf("Table1") - 32;
        //    content = content.Substring(begin, end);
        //    HtmlDocument doc = new HtmlDocument();
        //    doc.DocumentNode.InnerHtml = "<td id=" + content;

        //    HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//*[@class='thanhpho_bgr thanhpho_ten']");
        //    string nameCity = nc[0].InnerText;

        //    nc = doc.DocumentNode.SelectNodes("//*[@class='left_ver_box']");
        //    HtmlNode n = nc[0].NextSibling.NextSibling;
        //    nc = n.ChildNodes[1].ChildNodes[1].ChildNodes[1].SelectNodes("//table");

        //    if (nc.Count == 22)
        //    {
        //        nc[4].Attributes.Add("class", "CurrentWeather");
        //        DetailPage.InnerHtml = "<div class='NameCity'>" + nameCity + "</div><br>"
        //                               + nc[4].OuterHtml + "<br><div class='TitleProvinceWeather'>Dự báo thời tiết 3 ngày tới</div><br>"
        //                               + nc[11].OuterHtml + "<br><div class='TitleProvinceWeather'>Số liệu lịch sử</div><br>" + nc[19].OuterHtml;
        //    }
        //    else
        //    {
        //        DetailPage.InnerHtml = "<div class='NameCity'>" + nameCity + "</div>"
        //                               + "<br><div class='TitleProvinceWeather'>Dự báo thời tiết 3 ngày tới</div><br>"
        //                               + nc[4].OuterHtml + "<br><div class='TitleProvinceWeather'>Số liệu lịch sử</div><br>" + nc[13].OuterHtml;
        //    }
        //}

        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    if (IsPostBack == false)
        //    {
        //        GetProvinceWeather(Request.QueryString["provinceid"]);
        //    }
        //}
    }
}